package com.ra.controller;


import com.ra.pojo.RespBean;
import com.ra.pojo.RespPageBean;
import com.ra.pojo.dto.ConditionDTO;
import com.ra.pojo.dto.PhotoAlbumAdminDTO;
import com.ra.pojo.dto.PhotoAlbumDTO;
import com.ra.service.IPhotoAlbumService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 相册 前端控制器
 * </p>
 *
 * @author 今晚几点睡_Ada
 * @since 2023-03-09
 */
@RestController
@Api(tags = "相册模块")
public class PhotoAlbumController {

    @Autowired
    private IPhotoAlbumService photoAlbumService;

    @ApiOperation(value = "查看后台相册列表")
    @GetMapping("/admin/photos/albums")
    public RespBean<RespPageBean<PhotoAlbumAdminDTO>> listPhotoAlbumBacks(ConditionDTO conditionDTO) {
        return RespBean.success(photoAlbumService.listPhotoAlbumsAdmin(conditionDTO));
    }

    @ApiOperation(value = "保存或更新相册")
    @PostMapping("/admin/photos/albums")
    public RespBean<?> saveOrUpdatePhotoAlbum(@Valid @RequestBody PhotoAlbumDTO photoAlbumDto) {
        photoAlbumService.saveOrUpdatePhotoAlbum(photoAlbumDto);
        return RespBean.success();
    }

    @ApiOperation(value = "根据id删除相册")
    @ApiImplicitParam(name = "albumId", value = "相册id", required = true, dataType = "Integer")
    @DeleteMapping("/admin/photos/albums/{albumId}")
    public RespBean<?> deletePhotoAlbumById(@PathVariable("albumId") Integer albumId) {
        photoAlbumService.deletePhotoAlbumById(albumId);
        return RespBean.success();
    }
    @ApiOperation(value = "根据id获取后台相册信息")
    @ApiImplicitParam(name = "albumId", value = "相册id", required = true, dataType = "Integer")
    @GetMapping("/admin/photos/albums/{albumId}/info")
    public RespBean<PhotoAlbumAdminDTO> getPhotoAlbumBackById(@PathVariable("albumId") Integer albumId) {
        return RespBean.success(photoAlbumService.getPhotoAlbumByIdAdmin(albumId));
    }

    @ApiOperation(value = "获取后台相册列表信息")
    @GetMapping("/admin/photos/albums/info")
    public RespBean<List<PhotoAlbumDTO>> listPhotoAlbumBackInfos() {
        return RespBean.success(photoAlbumService.listPhotoAlbumInfosAdmin());
    }
    @ApiOperation(value = "获取相册列表")
    @GetMapping("/photos/albums")
    public RespBean<List<PhotoAlbumDTO>> listPhotoAlbums() {
        return RespBean.success(photoAlbumService.listPhotoAlbums());
    }



}

